var express = require('express');
var router = express.Router();

const Type = require('../db/type')

router.post('/type', function(req, res,body) {
  console.log(req.body);
  let {type} = req.body

  Type.find({type},function(err,data){
    if(!err){
      if(data.length===0){
         new Type({
            type
          }).save()
        res.send({
          code:200,
          mgs:"添加成功"
        })
      }else{
        res.send({
          code:201,
          msg:"已有该分类"
        })
      }
    }
  })

});

module.exports = router;